home *** CD-ROM | disk | FTP | other *** search
/ Java Primer Plus / Java Primer Plus (Waite Group Proess)(1996).iso / java_Win / demo / ImageMap / ImageMapArea.class (.txt) < prev    next >
Encoding:
Java Class File  |  1995-10-12  |  3.7 KB  |  104 lines

  1. import java.awt.Graphics;
  2. import java.awt.Image;
  3. import java.awt.image.ImageObserver;
  4. import java.net.URL;
  5. import java.util.StringTokenizer;
  6.  
  7. class ImageMapArea implements ImageObserver {
  8.    ImageMap parent;
  9.    // $FF: renamed from: X int
  10.    int field_0;
  11.    // $FF: renamed from: Y int
  12.    int field_1;
  13.    // $FF: renamed from: W int
  14.    int field_2;
  15.    // $FF: renamed from: H int
  16.    int field_3;
  17.    boolean entered = false;
  18.    boolean active = false;
  19.    boolean terminal = true;
  20.    Image hlImage;
  21.  
  22.    public void init(ImageMap parent, String args) {
  23.       this.parent = parent;
  24.       StringTokenizer st = new StringTokenizer(args, ", ");
  25.       this.field_0 = Integer.parseInt(st.nextToken());
  26.       this.field_1 = Integer.parseInt(st.nextToken());
  27.       this.field_2 = Integer.parseInt(st.nextToken());
  28.       this.field_3 = Integer.parseInt(st.nextToken());
  29.       if (st.hasMoreTokens()) {
  30.          this.handleArg(st.nextToken(""));
  31.       } else {
  32.          this.handleArg((String)null);
  33.       }
  34.  
  35.       this.makeImages();
  36.    }
  37.  
  38.    public void handleArg(String s) {
  39.    }
  40.  
  41.    public void setHighlight(Image img) {
  42.       this.hlImage = img;
  43.    }
  44.  
  45.    public void makeImages() {
  46.       this.setHighlight(this.parent.getHighlight(this.field_0, this.field_1, this.field_2, this.field_3));
  47.    }
  48.  
  49.    public boolean inside(int x, int y) {
  50.       return x >= this.field_0 && x < this.field_0 + this.field_2 && y >= this.field_1 && y < this.field_1 + this.field_3;
  51.    }
  52.  
  53.    public void drawImage(Graphics g, Image img, int imgx, int imgy, int x, int y, int w, int h) {
  54.       Graphics ng = g.create();
  55.       ng.clipRect(x, y, w, h);
  56.       ng.drawImage(img, imgx, imgy, this);
  57.    }
  58.  
  59.    public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
  60.       return img == this.hlImage ? this.parent.imageUpdate(img, infoflags, x + this.field_0, y + this.field_1, width, height) : false;
  61.    }
  62.  
  63.    public void showStatus(String msg) {
  64.       this.parent.getAppletContext().showStatus(msg);
  65.    }
  66.  
  67.    public void showDocument(URL u) {
  68.       this.parent.getAppletContext().showDocument(u);
  69.    }
  70.  
  71.    public void highlight(Graphics g, boolean on) {
  72.       if (on) {
  73.          g.drawImage(this.hlImage, this.field_0, this.field_1, this);
  74.       } else {
  75.          this.drawImage(g, this.parent.baseImage, 0, 0, this.field_0, this.field_1, this.field_2, this.field_3);
  76.       }
  77.    }
  78.  
  79.    public void setState(Graphics g, boolean on) {
  80.       this.highlight(g, on);
  81.       this.active = on;
  82.    }
  83.  
  84.    public void press(int x, int y) {
  85.       this.press();
  86.    }
  87.  
  88.    public void press() {
  89.    }
  90.  
  91.    public void lift(int x, int y) {
  92.       this.lift();
  93.    }
  94.  
  95.    public void lift() {
  96.    }
  97.  
  98.    public void drag(int x, int y) {
  99.    }
  100.  
  101.    public ImageMapArea() {
  102.    }
  103. }
  104.